home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Kodak Picture CD: 357069
/
Kodak Picture CD 357069.iso
/
setup
/
ksu
/
ksu.cab
/
pacsupport.js
< prev
next >
Wrap
Text File
|
2004-02-13
|
12KB
|
463 lines
// Dummy 'alert' function (supported by IE):
function alert() {}
// Note that 'helper' will be defined before including this code
// Resolve a host name:
function dnsResolve(host) { return helper.dnsResolve(host); }
// Get local IP address:
function myIpAddress() { return helper.myIpAddress(); }
// Check if a host name can be resolved:
function isResolvable(host) { return helper.isResolvable(host); }
// Cehck if the IP address of the host matches the spcified IP address pattern:
function isInNet(host, pattern, mask) { return helper.isInNet(host, pattern, mask); }
// Check if a given host name is plain (no dots):
function isPlainHostName(host)
{
return (host.search(/\./) == -1);
}
// Check if the given host name belongs to the given domain:
function dnsDomainIs(host, domain)
{
if (domain.length > host.length)
return false;
return (host.substr(host.length - domain.length) == domain);
}
// Check if given host name matches the fully qualified host name (host + domain):
function localHostOrDomainIs(host, hostdom)
{
if (host == hostdom)
return true;
var spHostdom = hostdom.split(".");
if (host == spHostdom[0])
return true;
return false;
}
// Number of DNS domains level in a host name (number of dots):
function dnsDomainLevels(host)
{
var ret = 0;
for (i = 0; i < host.length; i++)
if (host.charAt(i) == '.')
ret++;
return ret;
}
// Match a shell expression:
// - Slash and backslash are interchangeable
// - Match is case insensitive
// - '*' is interpreted and "any sequence of characters"
function shExpMatch(str, shexp)
{
// Build a regular expression:
var star = /\*/g;
var slash = /\/|\\/g;
var dot = /\./g;
var regexpstr = shexp;
regexpstr = regexpstr.replace(slash, "[/\\\\]");
regexpstr = regexpstr.replace(dot, "\\.");
regexpstr = regexpstr.replace(star, ".*");
var regexp = new RegExp(regexpstr, "i"); // case insensitive
var result = str.match(regexp);
if (result == null)
return false;
return (result[0] == str); // true only if regexp matchs the complete string
}
// Auxiliary function to find the index of a given weekday (0-6):
function findWeekdayIndex(wd)
{
var weekdays = new Array("SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT");
for (i = 0; i < 7; i++) {
if (wd == weekdays[i])
return i;
}
return -1;
}
// Check if the current weekday is within the given range.
function weekdayRange()
{
var now = new Date();
var nargs = arguments.length;
if (nargs == 1) {
var index = findWeekdayIndex(arguments[0]);
if (index == -1)
return false; // given weekday is invalid
return (now.getDay() == index);
}
else if (nargs == 2) {
if (arguments[1] == "gmt") {
var index = findWeekdayIndex(arguments[0]);
if (index == -1)
return false;
return (now.getUTCDay() == index);
}
else {
var wd1 = findWeekdayIndex(arguments[0]);
var wd2 = findWeekdayIndex(arguments[1]);
if (wd1 == -1 || wd2 == -1)
return false;
if (wd2 >= wd1) // e.g. SUN-WED
return (now.getDay() >= wd1 && now.getDay() <= wd2);
else // e.g. WED-SUN
return (now.getDay() >= wd1 || now.getDay() <= wd2);
}
}
else if (nargs == 3) {
if (arguments[2] != "gmt")
return false;
var wd1 = findWeekdayIndex(arguments[0]);
var wd2 = findWeekdayIndex(arguments[1]);
if (wd1 == -1 || wd2 == -1)
return false;
if (wd2 >= wd1) // e.g. SUN-WED
return (now.getUTCDay() >= wd1 && now.getUTCDay() <= wd2);
else // e.g. WED-SUN
return (now.getUTCDay() >= wd1 || now.getUTCDay() <= wd2);
}
else
return false;
}
// Auxiliary function to find the index of a given month (0-11):
function findMonthIndex(month)
{
var months = new Array("JAN", "FEB", "MAR", "APR", "MAY", "JUN",
"JUL", "AUG", "SEP", "OCT", "NOV", "DEC");
for (i = 0; i < 12; i++) {
if (month == months[i])
return i;
}
return -1;
}
// Check if the current date is within the given range.
function dateRange()
{
var now = new Date();
var nargs = arguments.length;
if (typeof(arguments[0]) == "string") {
// First argument is a month
if (nargs == 1) {
var index = findMonthIndex(arguments[0]);
if (index == -1)
return false; // given month is invalid
else
return (now.getMonth() == index);
}
else if (nargs == 2) {
if (arguments[1] == "gmt") {
var index = findMonthIndex(arguments[0]);
if (index == -1)
return false;
else
return (now.getUTCMonth() == index);
}
else {
var from = findMonthIndex(arguments[0]);
var to = findMonthIndex(arguments[1]);
if (from == -1 || to == -1)
return false;
return (now.getMonth() >= from && now.getMonth() <= to);
}
}
else if (nargs == 3) {
if (arguments[2] == "gmt") {
var from = findMonthIndex(arguments[0]);
var to = findMonthIndex(arguments[1]);
if (from == -1 || to == -1)
return false;
return (now.getUTCMonth() >= from && now.getMonth() <= to);
}
else
return false;
}
else if (nargs == 4) {
var m1 = findMonthIndex(arguments[0]);
var y1 = arguments[1];
var m2 = findMonthIndex(arguments[2]);
var y2 = arguments[3];
if (m1 == -1 || m2 == -1)
return false;
if ((now.getFullYear() < y1) ||
(now.getFullYear() == y1 && now.getMonth() < m1) )
return false; // not yet;
if ((now.getFullYear() > y2) ||
(now.getFullYear() == y2 && now.getMonth() > m2) )
return false; // already past
return true;
}
else if (nargs == 5) {
if (arguments[4] != "gmt")
return false;
var m1 = findMonthIndex(arguments[0]);
var y1 = arguments[1];
var m2 = findMonthIndex(arguments[2]);
var y2 = arguments[3];
if (m1 == -1 || m2 == -1)
return false;
if ((now.getUTCFullYear() < y1) ||
(now.getUTCFullYear() == y1 && now.getUTCMonth() < m1) )
return false; // not yet;
if ((now.getUTCFullYear() > y2) ||
(now.getUTCFullYear() == y2 && now.getUTCMonth() > m2) )
return false; // already past
return true;
}
else // invalid number of arguments
return false;
}
if (typeof(arguments[0]) != "number")
return false;
if (arguments[0] <= 31) {
// First argument is a day
if (nargs == 1) {
return (now.getDate() == arguments[0]);
}
else if (nargs == 2) {
if (arguments[1] == "gmt")
return (now.getUTCDate() == arguments[0]);
else
return (now.getDate() >= arguments[0] && now.getDate() <= arguments[1]);
}
else if (nargs == 3) {
if (arguments[2] == "gmt")
return (now.getUTCDate() >= arguments[0] && now.getUTCDate() <= arguments[1]);
else
return false;
}
else if (nargs == 4) {
var d1 = arguments[0];
var m1 = findMonthIndex(arguments[1]);
var d2 = arguments[2];
var m2 = findMonthIndex(arguments[3]);
if (m1 == -1 || m2 == -1)
return false;
if ((now.getMonth() < m1) ||
(now.getMonth() == m1 && now.getDate() < d1) )
return false; // not yet;
if ((now.getMonth() > m2) ||
(now.getMonth() == m2 && now.getDate() > d2) )
return false; // already past
return true;
}
else if (nargs == 5) {
if (arguments[4] != "gmt")
return false;
var d1 = arguments[0];
var m1 = findMonthIndex(arguments[1]);
var d2 = arguments[2];
var m2 = findMonthIndex(arguments[3]);
if (m1 == -1 || m2 == -1)
return false;
if ((now.getUTCMonth() < m1) ||
(now.getUTCMonth() == m1 && now.getUTCDate() < d1) )
return false; // not yet;
if ((now.getUTCMonth() > m2) ||
(now.getUTCMonth() == m2 && now.getUTCDate() > d2) )
return false; // already past
return true;
}
else if (nargs == 6) {
var d1 = arguments[0];
var m1 = findMonthIndex(arguments[1]);
var y1 = arguments[2]
var d2 = arguments[3];
var m2 = findMonthIndex(arguments[4]);
var y2 = arguments[5];
if (m1 == -1 || m2 == -1)
return false;
if ((now.getFullYear() < y1) ||
(now.getFullYear() == y1 && now.getMonth() < m1) ||
(now.getFullYear() == y1 && now.getMonth() == m1 && now.getDate() < d1) )
return false; // not yet;
if ((now.getFullYear() > y2) ||
(now.getFullYear() == y2 && now.getMonth() > m2) ||
(now.getFullYear() == y2 && now.getMonth() == m2 && now.getDate() > d2) )
return false; // already past
return true;
}
else if (nargs == 7) {
if (arguments[6] != "gmt")
return false;
var d1 = arguments[0];
var m1 = findMonthIndex(arguments[1]);
var y1 = arguments[2]
var d2 = arguments[3];
var m2 = findMonthIndex(arguments[4]);
var y2 = arguments[5];
if (m1 == -1 || m2 == -1)
return false;
if ((now.getUTCFullYear() < y1) ||
(now.getUTCFullYear() == y1 && now.getUTCMonth() < m1) ||
(now.getUTCFullYear() == y1 && now.getUTCMonth() == m1 && now.getUTCDate() < d1) )
return false; // not yet;
if ((now.getUTCFullYear() > y2) ||
(now.getUTCFullYear() == y2 && now.getUTCMonth() > m2) ||
(now.getUTCFullYear() == y2 && now.getUTCMonth() == m2 && now.getUTCDate() > d2) )
return false; // already past
return true;
}
else
return false;
}
else {
// First argument is a year
if (nargs == 1) {
return (now.getFullYear() == arguments[0]);
}
else if (nargs == 2) {
return (now.getFullYear() >= arguments[0] && now.getFullYear() <= arguments[1]);
}
else if (nargs == 3) {
if (arguments[2] != "gmt")
return false;
return (now.getUTCFullYear() >= arguments[0] && now.getUTCFullYear() <= arguments[1]);
}
else
return false;
}
}
// Check if the current time is within the given time range.
function timeRange()
{
var now = new Date();
var h1, h2, min1 = 0, min2 = 59, sec1 = 0, sec2 = 59;
var gmt = 0;
switch (arguments.length)
{
case 1:
h1 = arguments[0];
h2 = h1 + 1;
break;
case 2:
if (typeof(arguments[1]) == "number") {
h1 = arguments[0];
h2 = arguments[1];
}
else {
h1 = arguments[0];
h2 = h1 + 1;
if (arguments[1] == "gmt")
gmt = 1;
}
break;
case 3:
h1 = arguments[0];
h2 = arguments[1];
if (arguments[2] == "gmt")
gmt = 1;
break;
case 4:
h1 = arguments[0];
min1 = arguments[1];
h2 = arguments[2];
min2 = arguments[3];
break;
case 5:
h1 = arguments[0];
min1 = arguments[1];
h2 = arguments[2];
min2 = arguments[3];
if (arguments[4] == "gmt")
gmt = 1;
break;
case 6:
h1 = arguments[0];
min1 = arguments[1];
sec1 = arguments[2];
h2 = arguments[3];
min2 = arguments[4];
sec2 = arguments[5];
break;
case 7:
h1 = arguments[0];
min1 = arguments[1];
sec1 = arguments[2];
h2 = arguments[3];
min2 = arguments[4];
sec2 = arguments[5];
if (arguments[6] == "gmt")
gmt = 1;
break;
default:
return false; // invalid parameters
}
if (gmt) {
if ((now.getUTCHours() < h1) ||
(now.getUTCHours() == h1 && now.getUTCMinutes() < min1) ||
(now.getUTCHours() == h1 && now.getUTCMinutes() == min1 && now.getUTCSeconds() < sec1) )
return false; // not yet
if ((now.getUTCHours() > h2) ||
(now.getUTCHours() == h2 && now.getUTCMinutes() > min2) ||
(now.getUTCHours() == h2 && now.getUTCMinutes() == min2 && now.getUTCSeconds() > sec2) )
return false; // already past
return true;
}
else {
if ((now.getHours() < h1) ||
(now.getHours() == h1 && now.getMinutes() < min1) ||
(now.getHours() == h1 && now.getMinutes() == min1 && now.getSeconds() < sec1) )
return false; // not yet
if ((now.getHours() > h2) ||
(now.getHours() == h2 && now.getMinutes() > min2) ||
(now.getHours() == h2 && now.getMinutes() == min2 && now.getSeconds() > sec2) )
return false; // already past
return true;
}
}